
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link href="/sap/demo.css" rel="stylesheet" type="text/css" />
    <script src="/sap/scripts/boot.js" type="text/javascript"></script>


    <style type="text/css">
        body{
            margin:0;padding:0;border:0;width:100%;height:100%;overflow:hidden;
        }
    </style>
</head>

<body>

<div style="width:800px;">
    <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" iconCls="icon-add" onclick="addRow()" plain="true" tooltip="增加...">增加</a>
                    <!--<a class="mini-button" iconCls="icon-remove" onclick="removeRow()" plain="true">删除</a>-->
                    <span class="separator"></span>
                    <a class="mini-button" iconCls="icon-save" onclick="saveData()" plain="true">保存</a>
                </td>
                <!--<td style="white-space:nowrap;">-->
                    <!--<input id="key" class="mini-textbox" emptyText="供应商名" style="width:150px;" onenter="onKeyEnter"/>-->
                    <!--<a class="mini-button" onclick="search()">查询</a>-->
                <!--</td>-->
            </tr>
        </table>
    </div>
</div>
<div id="datagrid1" class="mini-datagrid" style="width:800px;height:280px;"
     url="SapSupplier/getitemprofitBeforeSale?item_id=<?php echo $_REQUEST['item_id'] ?>" idField="id"
     allowResize="true" pageSize="100"
     allowCellEdit="true" allowCellSelect="true" multiSelect="true"
     editNextOnEnterKey="true"

>
    <div property="columns">
        <div type="indexcolumn"></div>
        <div type="checkcolumn"></div>
        <!--ComboBox：本地数据-->
        <!--<div type="comboboxcolumn" autoShowPopup="true" name="gender" field="gender" width="100" allowSort="true"  align="center" headerAlign="center">性别-->
            <!--<input property="editor" class="mini-combobox" style="width:100%;" data="Genders" />-->
        <!--</div>-->


        <div header="物料号(OA)" field="item_id"><input property="readonly" class="mini-textbox" style="width:100%;"/>
        </div>

        <div header="毛利表名称*" field="profit_name"><input property="editor" class="mini-textbox" style="width:100%;"/></div>

        <!--ComboBox：远程数据-->
        <div type="comboboxcolumn" field="Customer_Code" width="100" headerAlign="center" >平台*
            <input property="editor" class="mini-combobox" style="width:100%;" url="/sale/getOCRDByCode" />
        </div>

            <div header="商城价*" field="mall_price"><input property="editor" class="mini-spinner" minValue="0"
                                                         maxValue="99999999"/></div>
            <div header="市场价" field="market_price"><input property="editor" class="mini-spinner" minValue="0"
                                                           maxValue="99999999"/></div>


            <div header="采购价" field="purchase_price"><input property="editor" class="mini-spinner" minValue="0"
                                                             maxValue="99999999"/></div>
            <div header="实际采购价" field="r_purchase_price"><input property="editor" class="mini-spinner" minValue="0"
                                                                 maxValue="99999999"/></div>
            <div header="分期数" field="by_stages"><input property="editor" class="mini-spinner" minValue="0"
                                                        maxValue="99999999"/></div>
            <div header="费率（%）" field="by_stages_rate"><input property="editor" class="mini-spinner" minValue="0"
                                                               maxValue="100"/></div>
            <div header="预估运费" field="freight"><input property="editor" class="mini-spinner" minValue="0"
                                                       maxValue="99999999"/></div>
            <div header="赠品价格" field="gift_price"><input property="editor" class="mini-spinner" minValue="0"
                                                          maxValue="99999999"/></div>
            <div header="银行佣金" field="bank_commission"><input property="editor" class="mini-spinner" minValue="0"
                                                               maxValue="99999999"/></div>
            <div header="包装费" field="packing_charge"><input property="editor" class="mini-spinner" minValue="0"
                                                             maxValue="99999999"/></div>
            <div header="返利金额" field="rebate"><input property="editor" class="mini-spinner" minValue="0"
                                                      maxValue="99999999"/></div>
            <div header="天猫" field="tamll"><input property="editor" class="mini-textbox" style="width:100%;"/></div>
            <div header="天猫销售数量" field="tamll_sale"><input property="editor" class="mini-textbox" style="width:100%;"/>
            </div>
            <div header="京东" field="jd"><input property="editor" class="mini-textbox" style="width:100%;"/></div>
            <div header="京东销售数量" field="jd_sale"><input property="editor" class="mini-textbox" style="width:100%;"/>
            </div>
            <div header="广发" field="guangfa"><input property="editor" class="mini-textbox" style="width:100%;"/></div>
            <div header="建行" field="jianhang"><input property="editor" class="mini-textbox" style="width:100%;"/></div>
            <div header="招行" field="zhaohang"><input property="editor" class="mini-textbox" style="width:100%;"/></div>
            <div header="交行" field="jiaohang"><input property="editor" class="mini-textbox" style="width:100%;"/></div>
            <div header="民生" field="minsheng"><input property="editor" class="mini-textbox" style="width:100%;"/></div>
            <div header="平安" field="pingan"><input property="editor" class="mini-textbox" style="width:100%;"/></div>
            <div header="中信" field="zhongxin"><input property="editor" class="mini-textbox" style="width:100%;"/></div>
            <div header="产品毛重(kg)" field="weight"><input property="editor" class="mini-textbox" style="width:100%;"/>
            </div>
            <div header="外包装尺寸" field="packing_size"><input property="editor" class="mini-textbox" style="width:100%;"/>
            </div>
            <!--<div header="推荐理由" field="recommended_reason"><input property="editor" class="mini-textbox"-->
                                                                  style="width:100%;"/></div>
            <!--<div header="赠品说明" field="gift_note"><input property="editor" class="mini-textbox" style="width:100%;"/>-->
            </div>


    </div>
</div>
<script type="text/javascript">

    mini.parse();

    var grid = mini.get("datagrid1");
    grid.load();

    //////////////////////////////////////////////////////

    function search() {
        var key = mini.get("key").getValue();
        grid.load({ sid: key });
    }

    function onKeyEnter(e) {
        search();
    }

    function addRow() {
        var newRow = { item_id: <?php echo $_REQUEST['item_id'] ?> };
        grid.addRow(newRow, 0);

        grid.beginEditCell(newRow, "mall_price");
    }
    function removeRow() {
        var rows = grid.getSelecteds();
        if (rows.length > 0) {
            grid.removeRows(rows, true);
        }
    }
    function saveData() {

        var data = grid.getChanges();
        var json = mini.encode(data);

        grid.loading("保存中，请稍后......");
        $.ajax({
            url: "../SapSupplier/updateitemprofitBeforeSale",
            data: { data: json },
            type: "post",
            success: function (text) {
                grid.reload();
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });
    }


    grid.on("celleditenter", function (e) {
        var index = grid.indexOf(e.record);
        if (index == grid.getData().length - 1) {
            var row = {};
            grid.addRow(row);
        }
    });

    grid.on("beforeload", function (e) {
        if (grid.getChanges().length > 0) {
            if (confirm("有增删改的数据未保存，是否取消本次操作？")) {
                e.cancel = true;
            }
        }
    });


            grid.on("cellcommitedit", function (e) {
                if (e.field == "profit_name") {
                    if (e.value == "testing") {
                        alert("毛利表名不允许为: testing");
                        e.cancel = true;
                    }
                }
            });



</script>

<script type="text/javascript">
    mini.parse();
    var grid2 = mini.get("datagrid1");

//    grid2.on("drawcell", function (e) {
//        var record = e.record,
//            column = e.column,
//            field = e.field,
//            value = e.value;
//        //格式化日期
//        if (field == "ctime") {
//            if (mini.isDate(value)) e.cellHtml = mini.formatDate(value, "yyyy-MM-dd HH:mm:ss");
//
//        }
//
//        if (field == "maoli") {
//            var zzs = (fmt(record.mall_price) - fmt(record.purchase_price)) * 0.07;
//            e.cellHtml = (fmt(record.mall_price) - fmt(record.purchase_price) + fmt(record.rebate) - fmt(record.freight) - fmt(record.gift_price) - fmt(record.bank_commission) - zzs).toFixed(2);
//        }
//
//        if (field == "maolilv") {
//            var zzs = (fmt(record.mall_price) - fmt(record.purchase_price)) * 0.07;
//            var maoli = (fmt(record.mall_price) - fmt(record.purchase_price) + fmt(record.rebate) - fmt(record.freight) - fmt(record.gift_price) - fmt(record.bank_commission) - zzs);
//
//            e.cellHtml = (maoli / fmt(record.mall_price) * 100).toFixed(2);
//
//        }
//
//        if (field == "zzs") {
//            var zzs = (fmt(record.mall_price) - fmt(record.purchase_price)) * 0.07;
//            e.cellHtml = (zzs).toFixed(2);
//
//        }
//
//        if (column.name == "action") {
//            e.cellStyle = "text-align:center";
//            e.cellHtml = '<a href="javascript:void(0)" onclick="deleteprofit(' + record.id + ')"/>删除</a>&nbsp; ';
//        }
//
//
//    });

</script>

</body>

</html>